package com.amorcloud.pig.activity;

import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.amorcloud.pig.R;
import com.amorcloud.pig.adapter.UsersAdapter;
import com.amorcloud.pig.bean.UserInfoBean;
import com.amorcloud.pig.utils.UserDaoUtils;

import java.util.List;

public class UserManagerActivity extends BaseActivity {

    ListView mUsersListView;
    List<UserInfoBean> mUsers;
    UsersAdapter mAdapter;
    TextView mAddUser;

    @Override
    protected void init() {
        setContentView(R.layout.activity_user_manager);
        initCustomToolbar(this);
        initView();
        initData();
    }

    private void initView() {
        mAddUser = findViewById(R.id.tv_add_user);
        mAddUser.setVisibility(View.VISIBLE);
        mUsersListView = findViewById(R.id.lv_user);
        View headerView = LinearLayout.inflate(this, R.layout.header_user, null);
        mUsersListView.addHeaderView(headerView);
    }

    private void initData() {
        mUsers = UserDaoUtils.queryAll();
        mAdapter = new UsersAdapter(this, mUsers);
        mUsersListView.setAdapter(mAdapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("leihuiming","onResume");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        mUsers = UserDaoUtils.queryAll();
        mAdapter.setData(mUsers);
        mAdapter.notifyDataSetChanged();
        Log.d("leihuiming","onRestart");
    }
}
